package top.kpromise.user.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import top.kpromise.user.model.response.UserModel;

@Repository
public interface UserMapper {

    @Select("select * from user where phone = #{phone} limit 1")
    UserModel findUserByPhone(String phone);

    @Select("select * from user where id = #{id} limit 1")
    UserModel findUserById(String id);

    @Select("select * from user where email = #{email} limit 1")
    UserModel findUserByEmail(String email);

    @Select("select * from user where email = #{loginValue} or phone = #{loginValue} limit 1")
    UserModel findUserByLoginValue(String loginValue);

    @Select("select count(*) from user where phone = #{phone}")
    int getUserCountByPhone(String phone);

    @Select("select count(*) from user where email = #{email}")
    int getUserCountByEmail(String email);

    @Select("select count(*) from user where id = #{id}")
    int getUserCountById(String id);

    @Insert("insert into user(id, phone, email) values (#{id}, #{phone}, #{email})")
    int insert(String id, String phone, String email);

    @Update("update user set enabled = #{enabled} where id = #{userId} limit 1")
    void updateEnableByUserId(String userId, int enabled);

    @Update("update user set phone = #{newPhone} where id = #{userId} limit 1")
    void updatePhone(String userId, String newPhone);

    @Update("update user set email = #{newEmail} where id = #{userId} limit 1")
    void updateEmail(String userId, String newEmail);
}